﻿using System;
using System.Collections.Generic;

using System.Text;

using System.IO;
using System.Reflection;

using MT.eVotePRS.Model;

namespace MT.eVotePRS.UI
{
    public sealed class Constants
    {
        public const int LEN_ID_Min = 8;
        public const int LEN_ID_Max = 12;

        public static string AppExeFullPath
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().CodeBase;
                // return Assembly.GetExecutingAssembly().GetName().FullName;
            }
        }

        public static string AppPath
        {
            get
            {
                return new DirectoryInfo(Path.GetDirectoryName(AppExeFullPath)).Parent.FullName;
            }
        }

        public static string AppConfigFileName
        {
            get
            {
                // return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Config\sys.config");
                return Path.Combine(appPath, @"Configuration\sys.config");
            }
        }

        public static string Log4NetConfigFileName
        {
            get
            {
                return Path.Combine(appPath, @"Configuration\log4net.config");
            }
        }

        public static string AppLogFile
        {
            get
            {
                return Path.Combine(appPath,"PRS.log");
            }
        }

        public static string appPath
        {
            get
            {
                string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

                if (Path.GetFileName(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)).ToUpper() == "RELEASE"
                    || Path.GetFileName(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)).ToUpper() == "DEBUG")
                    path = Path.GetDirectoryName(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath));

                if (Path.GetFileName(path).ToUpper() == "BIN")
                    path = Path.GetDirectoryName(path);

                path = path.Trim();

                if (path.Substring(path.Length - 1, 1) != @"\")
                    path += @"\";

                return path;
            }
        }

        #region Assemblys

        public static string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public static string AssemblyVersion
        {
            get
            {
                return string.Format("{0}.{1}.{2}", Assembly.GetExecutingAssembly().GetName().Version.Major, Assembly.GetExecutingAssembly().GetName().Version.Minor, Assembly.GetExecutingAssembly().GetName().Version.Build); // Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public static string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public static string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public static string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public static string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion
    }
}
